<!--
 * @Author: 陈伟 chenwei@duoliheng.com
 * @Date: 2022-12-29 14:56:01
 * @LastEditors: 陈伟 chenwei@duoliheng.com
 * @LastEditTime: 2022-12-29 16:07:11
 * @FilePath: \cool.front\src\views\safetySupervise\noCheckCsmSearch\components\rapidExecution.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <el-dialog
      v-el-drag-dialog
      title="一键下发安检任务"
      :visible.sync="visible"
      width="80%"
      @closed="reset"
    >
      <lb-table
        ref="lbTable"
        v-loading="$loadingPlugin.fetchData"
        class="table"
        border
        highlight-current-row
        element-loading-text="加载中"
        :column="tableData.column"
        :data="tableData.data"
        pagination
        :total="tableData.total"
        custom-column
        :immediate-fetch="false"
        @fetch="fetchData"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="save()">
          提交
        </el-button>
        <el-button @click="visible = false">
          关闭
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { selectBatchToCheckList, saveBathCheckPlan } from '@/api'
  export default {
    name: '',
    components: {},
    data() {
      return {
        visible: false,
        tableData: {
          total: 0,
          column: [
            {
              type: 'index',
              width: 30
            },
            {
              label: '客户编号',
              prop: 'csmCode',
              width: 100
            //   render: (h, { row }) => <el-link underline={false} onClick={() => this.openCsmDetail(row)}>{row.csmCode}</el-link>
            },
            { label: '客户名称', prop: 'csmName', width: 100 },
            { label: '联系人', prop: 'contact', minWidth: 110 },
            { label: '联系电话', prop: 'csmRgPhone', minWidth: 110 },
            { label: '身份证号', prop: 'sfzh', minWidth: 110 },
            { label: '联系地址', prop: 'csmAddress', width: 300 },
            { label: '上次安检机构', prop: 'lastCheckOrgName', width: 150 },
            { label: '处理人', prop: 'lastCheckUser', minWidth: 110 },
            {
              label: '操作',
              align: 'center',
              fixed: 'right',
              render: (h, { row, $index }) => {
                return (<div><el-link underline={false} onClick={() => { this.remove(row, $index) }}>删除</el-link></div>)
              }
            }
          ],
          data: []
        }
      }
    },
    computed: {},
    created() {
    },
    mounted() {},
    methods: {
      async open(temp) {
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
          //   console.log(temp)
          this.temp = temp
          this.fetchData({ currentPage: 1 })
        })
      },
      async fetchData({ currentPage, pageSize }) {
        const params = []
        await this.temp.forEach(e => {
          params.push(e.csmAddressId)
        })
        //   console.log('params',params.join(','))
        const res = await selectBatchToCheckList({ csmAddressIdList: params.join(','), currentPage, pageSize })
        this.tableData.data = res.data.rows
        if (currentPage === 1) this.tableData.total = res.data.total
      },
      remove(row, index) {
        this.tableData.data.splice(index, 1)
      },
      async save() {
        if (!this.tableData.data.length) {
          this.$message.warning('没有可提交的数据')
          return
        }
        const box = []
        await this.tableData.data.forEach(item => {
          const i = {
            csmCode: item.csmCode,
            csmPhone: item.csmRgPhone,
            contact: item.contact,
            csmAddressId: item.csmAddressId
          }
          box.push(i)
        })
        saveBathCheckPlan(box).then(res => {
          this.$message({
            title: '提示',
            message: '提交成功',
            type: 'success',
            duration: 2000
          })
          // 更新列表数据
          this.visible = false
          this.$emit('upDataTable')
        })
      },
      reset() {

      }
    }
  }

</script>
<style lang='scss' scoped>
</style>
